package com.joker.microstoremanager.controller;

import com.joker.common.model.JokerResponse;
import com.joker.microstoremanager.model.Goods;
import com.joker.microstoremanager.model.MicroShop;
import com.joker.microstoremanager.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.transaction.Transactional;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsManagerController {
    @Resource
    private GoodsService goodsService;

    @RequestMapping("typeAdd")
    public JokerResponse<String> addGoodsType(Goods g){
        MicroShop user = (MicroShop) SecurityContextHolder.getContext()
                .getAuthentication()
                .getPrincipal();
        goodsService.addType(user,g);
        return new JokerResponse<>();
    }

    @RequestMapping(value = "goodsDelete")
    @Transactional
    public JokerResponse<String> deleteGoods(Long id){
        goodsService.deleteGoods(id);
        return new JokerResponse<>();
    }


}
